package org.reenscape.skill;
import org.reenscape.model.*;
import org.reenscape.lib.*;
import org.reenscape.updater.*;
public class Smithing {

  // 1-Dagger, 2-Axe, 3-Chainbody, 4-Medhelm, 5-Dart tip, 6-Sword, 7-Mace, 8-Platelegs, 9-Full Helm, 10-Arrowtips,
  // 11-Scimitar, 12-Warhammer, 13-Plateskirt, 14-Sq. Sheild, 15-Knife, 16-Longsword, 17-Battleaxe, 18-Platebody,
  // 19-Kiteshield, 20-Nails, 21-2Hander, 22-Claws, 23-Oil Lantern Frame, 24-Studs
  public int[] SmithItem = { 
    /* 1    2     3     4     5    6     7     8     9   10    11    12    13    14    15    16    17    18    19    20    21    22    23    24*/
    1205, 1351, 1103, 1139, 819, 1277, 1422, 1075, 1155, 39, 1321, 1337, 1087, 1173, 864 , 1291, 1375, 1117, 1189, 4819, 1307, 3095, /* Bronze  00 */
    1203, 1349, 1101, 1137, 820, 1279, 1420, 1067, 1153, 40, 1323, 1335, 1081, 1175, 863 , 1293, 1363, 1115, 1191, 4820, 1309, 3096, /* Iron    22 */
    1207, 1353, 1105, 1141, 821, 1281, 1424, 1069, 1157, 41, 1325, 1339, 1083, 1177, 865 , 1295, 1365, 1119, 1193, 1539, 1311, 3097, /* Steel   44 */
    1209, 1355, 1109, 1143, 822, 1285, 1428, 1071, 1159, 42, 1329, 1343, 1085, 1181, 866 , 1299, 1369, 1121, 1197, 4822, 1315, 3099, /* Mithril 66 */
    1211, 1357, 1111, 1145, 823, 1287, 1430, 1073, 1161, 43, 1331, 1345, 1091, 1183, 867 , 1301, 1371, 1123, 1199, 4823, 1317, 3100, /* Addy    88 */
    1213, 1359, 1113, 1147, 824, 1289, 1432, 1079, 1163, 44, 1333, 1347, 1093, 1185, 868 , 1303, 1373, 1127, 1201, 4824, 1319, 3101  /* Rune   110 */
  };
  public int[] SmithLevel = {
  // 1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22   
    1 , 1 , 11, 3 , 4 , 4 , 2 , 16, 7 , 5 , 5 , 9 , 16, 8 , 7 , 6 , 10, 18, 12, 4 , 14, 13,   /* Bronze  */
    15, 15, 26, 18, 19, 19, 17, 31, 22, 20, 20, 24, 31, 23, 22, 21, 25, 33, 27, 19, 29, 28,   /* Iron    */
    30, 30, 41, 33, 34, 34, 32, 46, 37, 35, 35, 39, 46, 38, 37, 36, 40, 48, 42, 34, 44, 43,   /* Steel   */
    50, 50, 61, 53, 54, 54, 52, 66, 57, 55, 55, 59, 66, 58, 57, 56, 60, 68, 62, 54, 64, 63,   /* Mith    */
    70, 70, 81, 73, 74, 74, 72, 86, 77, 75, 75, 79, 86, 78, 77, 76, 80, 88, 82, 74, 84, 83,   /* Addy    */
    85, 85, 96, 88, 89, 89, 87, 99, 92, 90, 90, 94, 99, 93, 92, 91, 95, 99, 97, 89, 99, 98    /* Rune    */
  };
// END CAN SMITH VARIABLES ---------------------------------------------------->
  
  public void initSmithing(int barType, PacketParser p3) {
    if ((barType == 2363 && p3.playerLevel[13] >= 85) ||
        (barType == 2361 && p3.playerLevel[13] >= 70) ||
        (barType == 2359 && p3.playerLevel[13] >= 50) ||
        (barType == 2353 && p3.playerLevel[13] >= 30) ||
        (barType == 2351 && p3.playerLevel[13] >= 15) ||
        (barType == 2349 && p3.playerLevel[13] >= 1)) {
      p3.outStream.createFrame(97);
      p3.outStream.writeWord(994);
      
// START HAS BARS ------------------------------------------------------------->
      String hasfive = "@red@";
      String hasthree = "@red@";
      String hastwo = "@red@";
      String hasone = "@red@";
      if(p3.amountOfItem(barType) >= 5) { hasfive = "@gre@";  }
      if(p3.amountOfItem(barType) >= 3) { hasthree = "@gre@"; }
      if(p3.amountOfItem(barType) >= 2) { hastwo = "@gre@";   }
      if(p3.amountOfItem(barType) >= 1) { hasone = "@gre@";   }
      // Has 1 bars
      p3.sendFrame126(hasone + "1bar" + hasone,1125);
      p3.sendFrame126(hasone + "1bar" + hasone,1126);
      p3.sendFrame126(hasone + "1bar" + hasone,1127);
      p3.sendFrame126(hasone + "1bar" + hasone,1124);
      p3.sendFrame126(hasone + "1bar" + hasone,1128);
      p3.sendFrame126(hasone + "1bar" + hasone,1129);
      p3.sendFrame126(hasone + "1bar" + hasone,1130);
      p3.sendFrame126(hasone + "1bar" + hasone,13357);
      p3.sendFrame126(hasone + "1bar" + hasone,1131);
      p3.sendFrame126(hasone + "1bar" + hasone,11459);
      // Has 2 bars
      p3.sendFrame126(hastwo + "2bar" + hastwo,1113);
      p3.sendFrame126(hastwo + "2bar" + hastwo,1116);
      p3.sendFrame126(hastwo + "2bar" + hastwo,1114);
      p3.sendFrame126(hastwo + "2bar" + hastwo,1089);
      p3.sendFrame126(hastwo + "2bar" + hastwo,8428);
      // Has 3 bars
      p3.sendFrame126(hasthree + "3bar" + hasthree,1109);
      p3.sendFrame126(hasthree + "3bar" + hasthree,1110);
      p3.sendFrame126(hasthree + "3bar" + hasthree,1118);
      p3.sendFrame126(hasthree + "3bar" + hasthree,1111);
      p3.sendFrame126(hasthree + "3bar" + hasthree,1095);
      p3.sendFrame126(hasthree + "3bar" + hasthree,1115);
      p3.sendFrame126(hasthree + "3bar" + hasthree,1090);
      // Has 5 bars
      p3.sendFrame126(hasfive + "5bars" + hasfive,1112);
// END HAS BARS --------------------------------------------------------------->
      
// START CAN SMITH ------------------------------------------------------------>
      if(barType == 2349) { //Bronze
        windowApperance1(p3, 0, false, false);
        windowApperance2(p3, 0, false, false);
        p3.sendFrame126("",1132);
        p3.sendFrame126("",1135);
        p3.sendFrame126("",11459);
        p3.sendFrame126("",11461);
      }
      if(barType == 2351) { //Iron
        windowApperance1(p3, 22, false, false);
        windowApperance2(p3, 22, false, false);
        p3.sendFrame126("",1132);
        p3.sendFrame126("",1135);
        p3.sendFrame126("",11459);
        p3.sendFrame126("",11461);
      }
      if(barType == 2353) { //Steel
        windowApperance1(p3, 44, true, true);
        windowApperance2(p3, 44, true, true);
        p3.sendFrame126("", 1133);
        p3.sendFrame126("",11459);
        p3.sendFrame126("",11461);
        p3.sendFrame126(hasone + "1bar" + hasone,1132);
        p3.sendFrame126(hasone + "1bar" + hasone,1135);
      }
      if(barType == 2359) { //Mith
        windowApperance1(p3, 66, false, false);
        windowApperance2(p3, 66, false, false);
        p3.sendFrame126("",1132);
        p3.sendFrame126("",1135);
        p3.sendFrame126("",11459);
        p3.sendFrame126("",11461);
      }
      if(barType == 2361) { //Addy
        windowApperance1(p3, 88, false, false);
        windowApperance2(p3, 88, false, false);
        p3.sendFrame126("",1132);
        p3.sendFrame126("",1135);
        p3.sendFrame126("",11459);
        p3.sendFrame126("",11461);
      }
      if(barType == 2363) { //Rune
        windowApperance1(p3, 110, false, false);
        windowApperance2(p3, 110, false, false);
        p3.sendFrame126("",1132);
        p3.sendFrame126("",1135);
        p3.sendFrame126("",11459);
        p3.sendFrame126("",11461);
      }
// END CAN SMITH -------------------------------------------------------------->
    } else {
      p3.sendMessage("You cant smith this bar!");
    }
  }

  public void addItemToSmith(int id, int slot, int column, int amount, PacketParser p3) {
    p3.outStream.createFrameVarSizeWord(34); // init item to smith screen
    p3.outStream.writeWord(column); // Column Across Smith Screen
    p3.outStream.writeByte(4); // Total Rows?
    p3.outStream.writeDWord(slot); // Row Down The Smith Screen
    p3.outStream.writeWord(id+1); // item
    p3.outStream.writeByte(amount); // how many there are?
    p3.outStream.endFrameVarSizeWord();
  }
  
  public void windowApperance1(PacketParser p3, int startAt, boolean SmithLantern, boolean SmithStuds) {
    if(p3.playerLevel[13] < SmithLevel[startAt+0]) { p3.sendFrame126("@red@Dagger@red@",1094); }
      else { p3.sendFrame126("@gre@Dagger@gre@",1094); }
    if(p3.playerLevel[13] < SmithLevel[startAt+1]) { p3.sendFrame126("@red@Axe@red@",1091); }
      else { p3.sendFrame126("@gre@Axe@gre@",1091); }
    if(p3.playerLevel[13] < SmithLevel[startAt+2]) { p3.sendFrame126("@red@Chain body@red@",1098); }
      else { p3.sendFrame126("@gre@Chain body@gre@",1098); }      
    if(p3.playerLevel[13] < SmithLevel[startAt+3]) { p3.sendFrame126("@red@Medium helm@red@",1102); }
      else { p3.sendFrame126("@gre@Medium helm@gre@",1102); }
    if(p3.playerLevel[13] < SmithLevel[startAt+4]) { p3.sendFrame126("@red@Dart tips@red@",1107); }
      else { p3.sendFrame126("@gre@Dart tips@gre@",1107); }
    if(p3.playerLevel[13] < SmithLevel[startAt+5]) { p3.sendFrame126("@red@Sword@red@",1085); }
      else { p3.sendFrame126("@gre@Sword@gre@",1085); }
    if(p3.playerLevel[13] < SmithLevel[startAt+6]) { p3.sendFrame126("@red@Mace@red@",1093); }
      else { p3.sendFrame126("@gre@Mace@gre@",1093); }
    if(p3.playerLevel[13] < SmithLevel[startAt+7]) { p3.sendFrame126("@red@Plate legs@red@",1099); }
      else { p3.sendFrame126("@gre@Plate legs@gre@",1099); }
    if(p3.playerLevel[13] < SmithLevel[startAt+8]) { p3.sendFrame126("@red@Full helm@red@",1103); }
      else { p3.sendFrame126("@gre@Full helm@gre@",1103); }
    if(p3.playerLevel[13] < SmithLevel[startAt+9]) { p3.sendFrame126("@red@Arrowtips@red@",1108); }
      else { p3.sendFrame126("@gre@Arrowtips@gre@",1108); }
    if(p3.playerLevel[13] < SmithLevel[startAt+10]) { p3.sendFrame126("@red@Scimitar@red@",1087); }
      else { p3.sendFrame126("@gre@Scimitar@gre@",1087); }
    if(p3.playerLevel[13] < SmithLevel[startAt+11]) { p3.sendFrame126("@red@Warhammer@red@",1083); }
      else { p3.sendFrame126("@gre@Warhammer@gre@",1083); }
    if(p3.playerLevel[13] < SmithLevel[startAt+12]) { p3.sendFrame126("@red@Plate skirt@red@",1099); }
      else { p3.sendFrame126("@gre@Plate skirt@gre@",1099); }
    if(p3.playerLevel[13] < SmithLevel[startAt+13]) { p3.sendFrame126("@red@Square shield@red@",1104); }
      else { p3.sendFrame126("@gre@Square shield@gre@",1104); }
    if(p3.playerLevel[13] < SmithLevel[startAt+14]) { p3.sendFrame126("@red@Throwing knives@red@",1106); }
      else { p3.sendFrame126("@gre@Throwing knives@gre@",1106); }
    if(p3.playerLevel[13] < SmithLevel[startAt+15]) { p3.sendFrame126("@red@Long sword@red@",1086); }
      else { p3.sendFrame126("@gre@Long sword@gre@",1086); }
    if(p3.playerLevel[13] < SmithLevel[startAt+16]) { p3.sendFrame126("@red@Battle axe@red@",1092); }
      else { p3.sendFrame126("@gre@Battle axe@gre@",1092); }
    if(p3.playerLevel[13] < SmithLevel[startAt+17]) { p3.sendFrame126("@red@Plate body@red@",1101); } 
      else { p3.sendFrame126("@gre@Plate body@gre@",1101); }
    if(p3.playerLevel[13] < SmithLevel[startAt+18]) { p3.sendFrame126("@red@Kite shield@red@",1105); }
      else { p3.sendFrame126("@gre@Kite shield@gre@",1105); }
    if(p3.playerLevel[13] < SmithLevel[startAt+19]) { p3.sendFrame126("@red@Nails@red@",13358); }
      else { p3.sendFrame126("@gre@Nails@gre@",13358); }
    if(p3.playerLevel[13] < SmithLevel[startAt+20]) { p3.sendFrame126("@red@2 hand sword@red@",1088); }
      else { p3.sendFrame126("@gre@2 hand sword@gre@",1088); }
    if(p3.playerLevel[13] < SmithLevel[startAt+21]) { p3.sendFrame126("@red@Claws@red@",8429); }
      else { p3.sendFrame126("@gre@Claws@gre@",8429); }
    if (SmithLantern) {
      if(p3.playerLevel[13] < SmithLevel[startAt+22]) { p3.sendFrame126("@red@Oil Lantern@red@",1096); }
        else { p3.sendFrame126("@gre@Oil Lantern@gre@",1096); }
    } else {
      p3.sendFrame126("", 1096);
    }
    if (SmithStuds) {
      if(p3.playerLevel[13] < SmithLevel[startAt+23] && SmithStuds) { p3.sendFrame126("@red@Studs@red@",1134); }
        else { p3.sendFrame126("@gre@Studs@gre@",1134); }
    } else {
      p3.sendFrame126("", 1134);
    }
  }
  
  public void windowApperance2(PacketParser p3, int startAt, boolean SmithLantern, boolean SmithStuds) {
    addItemToSmith(SmithItem[startAt+0], 0, 1119, 1 , p3); // Dagger
    addItemToSmith(SmithItem[startAt+1], 0, 1120, 1 , p3); // Woodcutting Axe
    addItemToSmith(SmithItem[startAt+2], 0, 1121, 1 , p3); // Chainbody
    addItemToSmith(SmithItem[startAt+3], 0, 1122, 1 , p3); // Med Helm
    addItemToSmith(SmithItem[startAt+4], 0, 1123, 10, p3); // Dart tip
    addItemToSmith(SmithItem[startAt+5], 1, 1119, 1 , p3); // Sword
    addItemToSmith(SmithItem[startAt+6], 1, 1120, 1 , p3); // Mace
    addItemToSmith(SmithItem[startAt+7], 1, 1121, 1 , p3); // Platelegs
    addItemToSmith(SmithItem[startAt+8], 1, 1122, 1 , p3); // Full Helm
    addItemToSmith(SmithItem[startAt+9], 1, 1123, 15, p3); // Arrowtips
    addItemToSmith(SmithItem[startAt+10], 2, 1119, 1 , p3); // Scimitar
    addItemToSmith(SmithItem[startAt+11], 2, 1120, 1 , p3); // Warhammer
    addItemToSmith(SmithItem[startAt+12], 2, 1121, 1 , p3); // Plateskirt
    addItemToSmith(SmithItem[startAt+13], 2, 1122, 1 , p3); // Sq. shield
    addItemToSmith(SmithItem[startAt+14], 2, 1123, 5 , p3); // Knife
    addItemToSmith(SmithItem[startAt+15], 3, 1119, 1 , p3); // Longsword
    addItemToSmith(SmithItem[startAt+16], 3, 1120, 1 , p3); // Battleaxe
    addItemToSmith(SmithItem[startAt+17], 3, 1121, 1 , p3); // Platebody
    addItemToSmith(SmithItem[startAt+18], 3, 1122, 1 , p3); // Kitesheild
    addItemToSmith(SmithItem[startAt+19], 4, 1122, 10, p3); // Nails
    addItemToSmith(SmithItem[startAt+20], 4, 1119, 1 , p3); // 2hander
    addItemToSmith(SmithItem[startAt+21], 4, 1120, 1 , p3); // Claws
    if (SmithLantern == true) { addItemToSmith(4540, 3, 1123, 1 , p3); } // Oil Lantern Frame
      else if (SmithLantern == false) { addItemToSmith(-1, 3, 1123, 0 , p3); }
    if (SmithStuds == true)   { addItemToSmith(2370, 4 ,1123, 10, p3); } // Studs
      else if (SmithStuds == false) { addItemToSmith(-1, 4, 1123, 0 , p3); }
  }
  
  public int removeBar(int removeID) {
    if(removeID == 1205 || removeID == 1351 || removeID == 1103 || removeID == 1139 || removeID == 819  || removeID == 1277 || removeID == 1422 ||
       removeID == 1075 || removeID == 1155 || removeID == 39   || removeID == 1321 || removeID == 1337 || removeID == 1087 || removeID == 1173 ||
       removeID == 864  || removeID == 1291 || removeID == 1375 || removeID == 1117 || removeID == 1189 || removeID == 1307 || removeID == 3095 ||
       removeID == 4819) {
      return 2349;
    }
    if(removeID == 1203 || removeID == 1349 || removeID == 1420 || removeID == 1137 || removeID == 1279 || removeID == 820  || removeID == 4820 ||
       removeID == 1323 || removeID == 40   || removeID == 1293 || removeID == 1153 || removeID == 863  || removeID == 1175 || removeID == 1335 ||
       removeID == 1363 || removeID == 1101 || removeID == 4540 || removeID == 1191 || removeID == 3096 || removeID == 1309 || removeID == 1067 ||
       removeID == 1081 || removeID == 1115) {
      return 2351;
    }
    if(removeID == 1207 || removeID == 3097 || removeID == 1353 || removeID == 1424 || removeID == 1141 || removeID == 1281 || removeID == 1325 ||
       removeID == 1295 || removeID == 1157 || removeID == 1177 || removeID == 1339 || removeID == 1365 || removeID == 1105 || removeID == 1193 ||
       removeID == 1069 || removeID == 1083 || removeID == 1311 || removeID == 1119 || removeID == 1539 || removeID == 821  || removeID == 41   ||
       removeID == 2 || removeID == 2370 || removeID == 865 || removeID == 4544) {
      return 2353;
    }
    if(removeID == 1209 || removeID == 3099 || removeID == 1355 || removeID == 1428 || removeID == 1143 || removeID == 1285 || removeID == 1329 ||
       removeID == 1299 || removeID == 1159 || removeID == 1181 || removeID == 1343 || removeID == 1369 || removeID == 1109 || removeID == 1197 ||
       removeID == 1071 || removeID == 1085 || removeID == 1315 || removeID == 1121 || removeID == 822  || removeID == 4822 || removeID == 42   ||
       removeID == 42   || removeID == 866) {
      return 2359;
    }
    if(removeID == 1211 || removeID == 3100 || removeID == 1430 || removeID == 1145 || removeID == 1287 || removeID == 1331 || removeID == 1301 ||
       removeID == 1161 || removeID == 1183 || removeID == 1371 || removeID == 1111 || removeID == 1073 || removeID == 1091 || removeID == 1317 ||
       removeID == 1123 || removeID == 823  || removeID == 4823 || removeID == 43   || removeID == 867  || removeID == 1199) {
      return 2361;
    }
    if(removeID == 1213 || removeID == 3101 || removeID == 1432 || removeID == 1147 || removeID == 1289 || removeID == 1333 || removeID == 1303 ||
       removeID == 1163 || removeID == 1185 || removeID == 1347 || removeID == 1373 || removeID == 1113 || removeID == 1201 || removeID == 1079 ||
       removeID == 1093 || removeID == 1319 || removeID == 1127 || removeID == 824  || removeID == 4824 || removeID == 44   || removeID == 868) {
      return 2363;
    }
    return 0;
  }
  
  public int getExp(int removeID) {
    if(removeID == 1205 || removeID == 1351 || removeID == 1103 || removeID == 1139 || removeID == 819  || removeID == 1277 || removeID == 1422 ||
       removeID == 1075 || removeID == 1155 || removeID == 39   || removeID == 1321 || removeID == 1337 || removeID == 1087 || removeID == 1173 ||
       removeID == 864  || removeID == 1291 || removeID == 1375 || removeID == 1117 || removeID == 1189 || removeID == 1307 || removeID == 3095 ||
       removeID == 4819) {
      return 12;
    }
    else if(removeID == 1203 || removeID == 1349 || removeID == 1420 || removeID == 1137 || removeID == 1279 || removeID == 820  || removeID == 4820 ||
       removeID == 1323 || removeID == 40   || removeID == 1293 || removeID == 1153 || removeID == 863  || removeID == 1175 || removeID == 1335 ||
       removeID == 1363 || removeID == 1101 || removeID == 4540 || removeID == 1191 || removeID == 3096 || removeID == 1309 || removeID == 1067 ||
       removeID == 1081 || removeID == 1115) {
      return 25;
    }
    else if(removeID == 1207 || removeID == 3097 || removeID == 1353 || removeID == 1424 || removeID == 1141 || removeID == 1281 || removeID == 1325 ||
       removeID == 1295 || removeID == 1157 || removeID == 1177 || removeID == 1339 || removeID == 1365 || removeID == 1105 || removeID == 1193 ||
       removeID == 1069 || removeID == 1083 || removeID == 1311 || removeID == 1119 || removeID == 1539 || removeID == 821  || removeID == 41   ||
       removeID == 2 || removeID == 2370 || removeID == 865 || removeID == 4544) {
      return 37;
    }
    else if(removeID == 1209 || removeID == 3099 || removeID == 1355 || removeID == 1428 || removeID == 1143 || removeID == 1285 || removeID == 1329 ||
       removeID == 1299 || removeID == 1159 || removeID == 1181 || removeID == 1343 || removeID == 1369 || removeID == 1109 || removeID == 1197 ||
       removeID == 1071 || removeID == 1085 || removeID == 1315 || removeID == 1121 || removeID == 822  || removeID == 4822 || removeID == 42   ||
       removeID == 42   || removeID == 866) {
      return 50;
    }
    else if(removeID == 1211 || removeID == 3100 || removeID == 1430 || removeID == 1145 || removeID == 1287 || removeID == 1331 || removeID == 1301 ||
       removeID == 1161 || removeID == 1183 || removeID == 1371 || removeID == 1111 || removeID == 1073 || removeID == 1091 || removeID == 1317 ||
       removeID == 1123 || removeID == 823  || removeID == 4823 || removeID == 43   || removeID == 867  || removeID == 1199) {
      return 62;
    }
    else if(removeID == 1213 || removeID == 3101 || removeID == 1432 || removeID == 1147 || removeID == 1289 || removeID == 1333 || removeID == 1303 ||
       removeID == 1163 || removeID == 1185 || removeID == 1347 || removeID == 1373 || removeID == 1113 || removeID == 1201 || removeID == 1079 ||
       removeID == 1093 || removeID == 1319 || removeID == 1127 || removeID == 824  || removeID == 4824 || removeID == 44   || removeID == 868) {
      return 75;
    } else { return 0; }
  }

  public int barsNeeded(int slot, int column) {
    if(column == 1119) {
      if(slot == 0 || slot == 1) return 1;
      if(slot == 2 || slot == 3) return 2;
      if(slot == 4) return 3;
    }
    if(column == 1120) {
      if(slot == 0 || slot == 1) return 1;
      if(slot == 2 || slot == 3) return 3;
      if(slot == 4) return 2;
    }
    if(column == 1121) {
      if(slot == 0 || slot == 1 || slot == 2) return 3;
      if(slot == 3) return 5;
      if(slot == 4) return 1;
    }
    if(column == 1122) {
      if(slot == 0 || slot == 4) return 1;
      if(slot == 1 || slot == 2) return 2;
      if(slot == 3) return 3;
    }
    if(column == 1123) {
      if(slot == 0 || slot == 1 || slot == 2 || slot == 3 || slot == 4) return 1;
    }
    return 0;
  }
  
  public boolean canSmith(int itemID, PacketParser p3, int interfaceID, int Slot, int barID) {
    if (p3.playerLevel[13] >= getNum(interfaceID, Slot, barID)) {
      return true;
    } else {
      return false;
    }
  }
  
  public int getNum(int interfaceID, int Slot, int barID) {
    int incBy = 0;
    if (barID == 2351) incBy = 22;
    else if (barID == 2353) incBy = 44;
    else if (barID == 2359) incBy = 66;
    else if (barID == 2361) incBy = 88;
    else if (barID == 2363) incBy = 110;
    if (interfaceID == 1119 && Slot == 0) { return SmithLevel[0+incBy]; } // Dagger
    else if (interfaceID == 1120 && Slot == 0) { return SmithLevel[1+incBy]; } // Woodcutting Axe
    else if (interfaceID == 1121 && Slot == 0) { return SmithLevel[2+incBy]; } // Chainbody
    else if (interfaceID == 1122 && Slot == 0) { return SmithLevel[3+incBy]; } // Med Helm
    else if (interfaceID == 1123 && Slot == 0) { return SmithLevel[4+incBy]; } // Dart tip
    else if (interfaceID == 1119 && Slot == 1) { return SmithLevel[5+incBy]; } // Sword
    else if (interfaceID == 1120 && Slot == 1) { return SmithLevel[6+incBy]; } // Mace
    else if (interfaceID == 1121 && Slot == 1) { return SmithLevel[7+incBy]; } // Platelegs
    else if (interfaceID == 1122 && Slot == 1) { return SmithLevel[8+incBy]; } // Full Helm
    else if (interfaceID == 1123 && Slot == 1) { return SmithLevel[9+incBy]; } // Arrowtips
    else if (interfaceID == 1119 && Slot == 2) { return SmithLevel[10+incBy]; } // Scimitar
    else if (interfaceID == 1120 && Slot == 2) { return SmithLevel[11+incBy]; } // Warhammer
    else if (interfaceID == 1121 && Slot == 2) { return SmithLevel[12+incBy]; } // Plateskirt
    else if (interfaceID == 1122 && Slot == 2) { return SmithLevel[13+incBy]; } // Sq. shield
    else if (interfaceID == 1123 && Slot == 2) { return SmithLevel[14+incBy]; } // Knife
    else if (interfaceID == 1119 && Slot == 3) { return SmithLevel[15+incBy]; } // Longsword
    else if (interfaceID == 1120 && Slot == 3) { return SmithLevel[16+incBy]; } // Battleaxe
    else if (interfaceID == 1121 && Slot == 3) { return SmithLevel[17+incBy]; } // Platebody
    else if (interfaceID == 1122 && Slot == 3) { return SmithLevel[18+incBy]; } // Kitesheild
    else if (interfaceID == 1119 && Slot == 4) { return SmithLevel[19+incBy]; } // Nails
    else if (interfaceID == 1120 && Slot == 4) { return SmithLevel[20+incBy]; } // 2hander
    else if (interfaceID == 1121 && Slot == 4) { return SmithLevel[21+incBy]; } // Claws
    else if (interfaceID == 1123 && Slot == 3) { return 26; } // Oil Lantern Frame
    else if (interfaceID == 1123 && Slot == 4) { return 34; } // Studs
    else { return 0; }
  }
  
  public void smithingMain(PacketParser p3, int removeSlot, int interfaceID, int removeID, int amount) {
    p3.smithing[0] = removeSlot;
    p3.smithing[1] = interfaceID;
    p3.smithing[2] = removeID;
    p3.smithing[3] = amount;
    p3.smithing[4] = 2;
  }
  
  public void reset(PacketParser p3) {
    p3.smithing[0] = 0;
    p3.smithing[1] = 0;
    p3.smithing[2] = 0;
    p3.smithing[3] = 0;
    p3.smithing[4] = 0;
  }
  
  public void makeItems(PacketParser p3) {
    int giveNum = 1;
    if(p3.smithing[0] == 4 && p3.smithing[1] == 1122) giveNum = 10;
    if(p3.smithing[0] == 0 && p3.smithing[1] == 1123) giveNum = 10;
    if(p3.smithing[0] == 1 && p3.smithing[1] == 1123) giveNum = 15;
    if(p3.smithing[0] == 2 && p3.smithing[1] == 1123) giveNum = 5;
    try {
      if(canSmith(p3.smithing[2], p3, p3.smithing[1], p3.smithing[0], removeBar(p3.smithing[2]))) {
        if(p3.playerHasItem(2348) == true) {
          if(barsNeeded(p3.smithing[0], p3.smithing[1]) <= removeBar(p3.smithing[2])) {
            p3.addSkillXP(barsNeeded(p3.smithing[0], p3.smithing[1])*getExp(p3.smithing[2]), 13);
            for (int q=0; q<barsNeeded(p3.smithing[0], p3.smithing[1]); q++) { p3.deleteItem(removeBar(p3.smithing[2]), p3.getItemSlotReturn(removeBar(p3.smithing[2])), 1); }
            p3.addItem(p3.smithing[2], giveNum);
            reset(p3);
          } else {
           p3.sendMessage("You do not have enough bars to make this item.");
           reset(p3);
          }
        } else {
          p3.sendMessage("You need a hammer to smith this item.");
          reset(p3);
        }
      } else {
        p3.sendMessage("You cannot smith this item.");
        reset(p3);
      }
    } catch(Exception e) {}
  }
  
  /*SMELTING*/
  public void makeItems2(PacketParser p3, int oreID) {
    int barID = 0;
    int barXP = 0;
    int barLvl = 0;
    int coalAmount = 0;
    int hasCoalAmount = 0;
    for (int i=0; i<28; i++) {
      if (p3.playerItems[i] == 454) {
        hasCoalAmount++;
      }
    }
    if (oreID == 436 || oreID == 438) { barID = 2349; barXP = 6; barLvl = 1; }  // Copper or Tin
    if (hasCoalAmount >= 2) {
      if (oreID == 440) { barID = 2353; barXP = 17; barLvl = 30; coalAmount = 2; }// Make steel
    } else {
      if (oreID == 440) { barID = 2351; barXP = 12; barLvl = 15; }  // Make iron
    }
    if (oreID == 442) { barID = 2355; barXP = 13; barLvl = 20; } // Silver
    if (oreID == 444) { barID = 2357; barXP = 22; barLvl = 40; } // Gold
    if (oreID == 447) { barID = 2359; barXP = 30; barLvl = 50; coalAmount = 4; } // Mithril
    if (oreID == 449) { barID = 2361; barXP = 37; barLvl = 70; coalAmount = 6; } // Addy
    if (oreID == 451) { barID = 2363; barXP = 50; barLvl = 85; coalAmount = 8; } // Rune
    // if (oreID == 668) barID = 23; // Blurite (Need bar ID)
    if (barLvl <= p3.playerLevel[13]) {
      if (hasCoalAmount >= coalAmount) {
        if (oreID == 436 || oreID == 438) {
          p3.deleteItem(436, p3.getItemSlotReturn(436), 1);
          p3.deleteItem(438, p3.getItemSlotReturn(438), 1);
        } else { p3.deleteItem(oreID, p3.getItemSlotReturn(oreID), 1); }
        for (int q=0; q<coalAmount; q++) {
          p3.deleteItem(453, p3.getItemSlotReturn(453), 1);
        }
        if (barID == 2351) {
          if (java.lang.Math.random() <= .5 || p3.playerEquipment[p3.playerRing] == 2568) {
            p3.addItem(barID, 1);
            p3.addSkillXP(barXP, 13);
            p3.sendMessage("You make a " + p3.GetItemName(barID) + ".");
          } else { p3.sendMessage("You failed to make a iron bar."); }
        } else {
          p3.addItem(barID, 1);
          p3.addSkillXP(barXP, 13);
          p3.sendMessage("You make a " + p3.GetItemName(barID) + ".");
        }
      } else {
        p3.sendMessage("You dont have enough coal.");
      }
    } else {
      p3.sendMessage("You need a level of " + barLvl + ".");
    }
  }
    
  public void SmeltingMain(PacketParser p3, int amount, int barID) {
    p3.smelting[0] = 4; // Time to make
    p3.smelting[1] = amount; // Amount
    p3.smelting[2] = barID; // Bar ID
  }
}